﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;

namespace Meraz.Core.Repositories
{
    public interface ITweetRepository : IRepository<Tweet, long>
    {
        List<Tweet> GetByUserID(long userID);
        List<Tweet> GetByUsername(string username);
    }
    public class TweetRepository : EFRepositoryBase<Tweet, long>, ITweetRepository
    {
        public override Tweet GetById(long id)
        {
            return context.Tweets
                .Where(where1 => where1.ID == id)
                .FirstOrDefault();
        }

        public List<Tweet> GetByUserID(long userID)
        {
            return context.Tweets
                .Where(where1 => where1.UserID == userID)
                .ToList();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        /// <remarks>Username will be different for Retweets</remarks>
        public List<Tweet> GetByUsername(string username)
        {
            return context.Tweets
                .Where(where1 => where1.Username == username)
                .ToList();
        }

        public override void Add(Tweet entity)
        {
            context.AddToTweets(entity);
        }

        public override void Delete(Tweet entity)
        {
            context.DeleteTweet(entity.ID);
        }

        public override List<Tweet> All()
        {
            return context.Tweets.ToList();
        }
    }
}
